/**
 * 
 */
package co.fitstart.mobile.dao.support;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.demo2do.core.persistence.GenericDaoSupport;
import com.demo2do.core.support.Page;

import co.fitstart.entity.credit.product.CreditProduct;
import co.fitstart.entity.credit.product.CreditProductTag;

/**
 * @author Guangli Yan
 *
 */
@Repository("creditMallDaoSupport")
public class CreditMallDaoSupport {

	@Autowired
	private GenericDaoSupport genericDaoSupport;

	/**
	 * @param tab
	 * @return
	 */
	public int count(CreditProductTag tab) {
		
		String sentence = "FROM CreditProduct WHERE disabled = false AND tags LIKE :tag ";

		Map<String, Object> map = new HashMap<>();

		map.put("tag", "%"+tab.getAlias()+"%");

		genericDaoSupport.searchForInt(sentence, map);

		return 0;
	}
	
	/**
	 * @param creditProductTag
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<CreditProduct> list(CreditProductTag creditProductTag) {

		String sentence = "FROM CreditProduct WHERE disabled = false AND tags LIKE :tag ";

		Map<String, Object> map = new HashMap<>();

		map.put("tag", "%"+creditProductTag.getAlias()+"%");

		List<CreditProduct> creditProductions = genericDaoSupport.searchForList(sentence, map);

		return creditProductions;
	}

	/**
	 * @param tab
	 * @param page
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<CreditProduct> list(CreditProductTag tab, Page page) {
		
		String sentence = "FROM CreditProduct WHERE disabled = false AND tags LIKE :tag ";
		
		Map<String, Object> map = new HashMap<>();

		map.put("tag", "%"+tab.getAlias()+"%");
		
		List<CreditProduct> result = genericDaoSupport.searchForList(sentence, map, page.getBeginIndex(), page.getMaxResultRecords());
		
		return result;
	}


}
